<template>

  <el-form-item label="文字描述">

    <textarea v-model="optionValue" style="width:100%" Rows="3"></textarea>
    <el-button type="primary"  @click="opendialog">确定</el-button>

  </el-form-item>
</template>

<script>
  export default {
    props: {
      value: {
        type: Object,
        default: null
      },
      config: {
        type: Object,
        default: null
      },
    },
    data() {
      return {
        optionValue:"",
        sp: {},
        sr: {},
        param: {},
      }
    },
    created(options) {
      let that = this;
      that.xinit();
    },
    methods: {
      opendialog() {
        let that = this;
        let value = that.optionValue;
        let valueDate = value.split("\n");
        let optionDate = [];
        valueDate.forEach((item,index)=>{
          let itemDate = item.split("/");
          let date = {}
          itemDate.forEach((v,i)=>{
            let d = {
              value: v,
              label: v,
              children:[],
            }
            if(i===0){
              date = d;
            }else if(i === 1){
              date.children.push(d)
            }else {
              date.children[0].children.push(d)
            }
          })
          optionDate.push(date);
        })
        let mergedData = that.cutarray(optionDate);
        this.activeData.csmwjselectcascader.value = mergedData;
      },
      cutarray(optionDate) {
        let that = this;
        // 使用 Array.reduce 合并具有相同name属性的geometry数据到数组中
        var mergedData = optionDate.reduce(function (result, currentData) {
          var value = currentData.value;
          var label = currentData.label;
          var children = currentData.children;

          // 查找结果数组中具有相同name属性的对象
          var existingItem = result.find(item => item.value === value);

          if (existingItem) {
            existingItem.children = that.cutarray(existingItem.children.concat(children));
            console.log(existingItem.children);
            // 如果找到，将当前数据的geometry数据添加到该对象的数组中
            // existingItem.geometryArray.push(children);
          } else {
            // 否则，创建一个新的对象，并将当前数据的geometry数据放入一个新的数组中
            result.push({
              value: value,
              label: label,
              children:children
            });
          }
          return result;
        }, []);

        return mergedData;
      },
      xinit() {
        let that = this;
      },
      // onInput: function(event) {
      //   let that = this;
      //   that.$emit("input", {
      //     value: event.target.value
      //   });
      // }
    }
  }
</script>

<style>

</style>
